﻿////////////////////////////////////////////////////////////////////////////
//
//  Immense Engine Source File.
//  Copyright (C), Indloon 2012
// -------------------------------------------------------------------------
//  File name:   iePlatform.h
//  Description: OS Defines, for dedicate server on Win, MacOSX and Linux.
//  Created:     15/02/2012 Genert Org
//  Compilers:   Visual C++ 2010 Express
// -------------------------------------------------------------------------
//  History:
//       08/02/2012 <Genert Org> - Rewrote the code
////////////////////////////////////////////////////////////////////////////
#ifndef __IMMENSEENGINE_PLATFORM_H
#define __IMMENSEENGINE_PLATFORM_H
#pragma once

/*  M A I N  D E F I N E S  &  I N C L U D E S
	=========================================================================== */
	
#define _CRT_SECURE_NO_DEPRECATE // MS VS

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <string.h>

/*
    32 bits (4-byte aligned)
	16 bits (2-byte aligned)
	8 bits (1-byte aligned)
*/
typedef __int32          shortshort;
typedef unsigned __int32 ushortshort; 
typedef __int64          longlong;
typedef unsigned __int64 ulonglong; 

typedef unsigned char    uchar;  // 8 - bits
typedef unsigned int     uint;   // 32 - bits
typedef unsigned short   ushort; // 16 - bits
typedef unsigned long    ulong;  // 64 - bits

typedef signed char      schar;
typedef signed int       sint;
typedef signed long      slong;

typedef uchar            byte;
typedef ushort           word;
typedef ulong            dword;
typedef ulonglong        qword;
typedef ushort           half;

// http://sourceforge.net/p/predef/wiki/OperatingSystems/
#if defined ( _WIN64 ) || defined( __WIN64__ )
    #define OS_WIN64
#endif

#if defined  ( _WIN32 ) || defined( __WIN32__ )
    #define OS_WIN32
#endif

#if defined ( MACOS_X ) || defined( __APPLE_CC__ )
    #define OS_MACOSX
#endif
	
#if defined ( __linux__ ) || defined( __FreeBSD_kernel__ )
    #define OS_LINUX
#endif	

// http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros
#if defined ( __ia64 ) || ( __ia64__ ) || ( __IA64__ ) || ( __itanium__ ) || ( _M_IA64 )
    #define _CPU_IA64
#endif

/*  O S
	=========================================================================== */
	
#if defined OS_WIN32

    #define Rectangle LCC_Rectangle
	#define WIN32_LEAN_AND_MEAN
	
    #ifndef VC_EXTRALEAN
	    #define VC_EXTRALEAN
	#endif
	
	#ifndef _WIN32_WINNT
        #define _WIN32_WINNT 0x501
    #endif
	
	// includes
	#include <malloc.h>
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <time.h>
	#include <Windows.h>
	#undef Rectangle
	
    typedef signed char       int8;
    typedef signed short      int16;
    typedef signed int        int32;
    typedef signed __int64    int64;
    typedef unsigned char     uint8;
    typedef unsigned short    uint16;
    typedef unsigned int      uint32;
    typedef unsigned __int64  uint64;
	
	typedef float             f32;
    typedef double            f64;
	
    #ifndef SAFE_DELETE
        #define SAFE_DELETE(p)			{ if(p) { delete (p);		(p)=NULL; } }
    #endif

    #ifndef SAFE_DELETE_ARRAY
        #define SAFE_DELETE_ARRAY(p)	{ if(p) { delete [] (p);		(p)=NULL; } }
    #endif
	
    #define ILINE						__forceinline
    #define NEWLINE                     "\r\n"
	#define DLL_EXT                     ".dll"
	#define PATH_SEPARATOR_STRING		"\\"
	#define PATH_SEPARATOR_CHAR			'\\'
	#define MAX_PATH                    260
	#define snprintf					_snprintf
    #define vsnprintf	                _vsnprintf
	
	#define _CASE_SENSITIVE_FILESYSTEM
	#define _LITTLE_ENDIAN
	
	#undef FindText
	#undef IsMinimized
	
#endif // OS_WIN32
// -------------------------------------------------------------------------------------------------------------
#if defined OS_WIN64

    #define Rectangle LCC_Rectangle
	#define WIN32_LEAN_AND_MEAN
	
    #ifndef VC_EXTRALEAN
	    #define VC_EXTRALEAN
	#endif
	
	#ifndef _WIN32_WINNT
        #define _WIN32_WINNT 0x501
    #endif
	
	// includes
	#include <malloc.h>
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <time.h>
	#include <Windows.h>
	#undef Rectangle
	
    typedef signed char        int8;
    typedef signed short       int16;
    typedef signed int         int32;
    typedef signed long long   int64;
    typedef unsigned char      uint8;
    typedef unsigned short     uint16;
    typedef unsigned int       uint32;
    typedef unsigned long long uint64;

	typedef float              f32;
    typedef double             f64;
	
	#ifndef SAFE_DELETE
		#define SAFE_DELETE(p)			{ if(p) { delete (p);		(p)=NULL; } }
	#endif

	#ifndef SAFE_DELETE_ARRAY
		#define SAFE_DELETE_ARRAY(p)	{ if(p) { delete [] (p);		(p)=NULL; } }
	#endif
	
	#define ILINE						__forceinline
    #define NEWLINE                     "\r\n"
	#define DLL_EXT                     ".dll"
	#define PATH_SEPARATOR_STRING		"\\"
	#define PATH_SEPARATOR_CHAR			'\\'
	#define MAX_PATH                    260
	#define snprintf					_snprintf
    #define vsnprintf	                _vsnprintf
	
	#define _CASE_SENSITIVE_FILESYSTEM
	#define _LITTLE_ENDIAN
	
	#undef FindText
	#undef IsMinimized
	
#endif // OS_WIN64
// -------------------------------------------------------------------------------------------------------------
#if defined OS_MACOSX

    #include <pthread.h>
	#include <stddef.h>

	typedef signed char        int8;
    typedef signed short       int16;
    typedef signed int         int32;
    typedef signed long long   int64;
    typedef unsigned char      uint8;
    typedef unsigned short     uint16;
    typedef unsigned int       uint32;
    typedef unsigned long long uint64;

	typedef float              f32;
    typedef double             f64;

	#define ILINE                      inline
	#define NEWLINE                     "\n"
	#define DLL_EXT                     ".dylib"
	#define PATH_SEPARATOR_STRING		"/"
	#define PATH_SEPARATOR_CHAR			'/'
	#define MAX_PATH                    1024

	#define _CASE_SENSITIVE_FILESYSTEM

	#if defined( __ppc__ )
		#undef _LITTLE_ENDIAN
	#else
		#define _LITTLE_ENDIAN
	#endif

#endif
// -------------------------------------------------------------------------------------------------------------
#if defined OS_LINUX

    #include <stdint.h>

    typedef signed char        int8;
    typedef signed short       int16;
    typedef signed int         int32;
    typedef signed long long   int64;
    typedef unsigned char      uint8;
    typedef unsigned short     uint16;
    typedef unsigned int       uint32;
    typedef unsigned long long uint64;

	typedef float              f32;
    typedef double             f64;

    #ifdef __clang__
        #define ILINE                   static inline
    #else
        #define ILINE                   inline
    #endif

    #define NEWLINE                     "\n"
	#define DLL_EXT                     ".so"
	#define PATH_SEPARATOR_STRING		"/"
	#define PATH_SEPARATOR_CHAR			'/'
	#define MAX_PATH                    4096

	#define _CASE_SENSITIVE_FILESYSTEM

	#define _LITTLE_ENDIAN

#endif
// -------------------------------------------------------------------------------------------------------------

#endif // __IMMENSEENGINE_PLATFORM_H